package org.jspar.model;

import java.util.HashMap;
import java.util.Map;

import org.jspar.Constants;
import org.jspar.tile.Rectangle;

public abstract class AsgModule {
	
	   public static final int NOT_ = 1;
	   public static final int AND = 2;
	   public static final int NAND = 3;
	   public static final int OR = 4;
	   public static final int NOR = 5;
	   public static final int XOR = 6;
	   public static final int XNOR = 7;
	   public static final int BUFFER = 8;
	   public static final int INPUT_SYM = 9;
	   public static final int OUTPUT_SYM = 10;
	   public static final int INOUT_SYM = 11;
	   public static final int BLOCK = 12;
	   public static final int INVNOT_ = 13;
	   public static final int NMOS = 14;
	   public static final int PMOS = 15;
	   public static final int CAPC = 16;
	   public static final int INDR = 17;
	   public static final int RESTR = 18;
	   public static final int VAMP	= 19;
	   public static final int MSFET	= 20;
	   public static final int DONT_KNOW = 21;

	public static final String GATE_AND_STR    = "AND";
	public static final String GATE_OR_STR     = "OR";
	public static final String GATE_NAND_STR   = "NAND";
	public static final String GATE_NOR_STR    = "NOR";
	public static final String GATE_XOR_STR    = "XOR";
	public static final String GATE_XNOR_STR   = "XNOR";
	public static final String GATE_NOT_STR    = "NOT";
	public static final String GATE_NMOS_STR   = "NMOS";
	public static final String GATE_PMOS_STR	= "PMOS";
	public static final String GATE_NMOS_4_STR = "NMOS_4";
	public static final String GATE_PMOS_4_STR	= "PMOS_4";
	public static final String GATE_CAPC_STR	= "CAPC";
	public static final String GATE_RESTR_STR	= "RESTR";
	public static final String GATE_INDR_STR	= "INDR";
	public static final String GATE_VAMP_STR   = "VAMP";
	public static final String GATE_IAMP_STR   = "IAMP";
	public static final String GATE_MSFET_STR  = "MSFET";
	public static final String GATE_INVNOT_STR = "INVNOT";
	public static final String GATE_VSOURCE	= "VSOURCE";
	public static final String GATE_ISOURCE	= "ISOURCE";
	public static final String GATE_NULL_STR  = "NL_GATE";
	
	public static final String  XNOR_GATE = "XNOR"	;
	public static final String  BUFFER_GATE = "BUFFER";
	public static final String  INPUT_TERM = "IN";
	public static final String  OUTPUT_TERM = "OUT";
	public static final String  INOUT_TERM = "INOUT";
	public static final String  OUTIN_TERM = "OUTIN";
	public static final String  GENERIC_BLOCK = "BLOCK";

	public static void set_default_object_size(Module mod) {
		/*switch (validate(mod.type())) {
		case BUFFER:
		case INVNOT_:
		case NOT_:
			mod.setXSize(Constants.GATE_HEIGHT);
			mod.setYSize(Constants.SYSTERM_SIZE);
			break;
		case AND:
		case NAND:
		case OR:
		case NOR:
		case XOR:
		case XNOR:
			mod.setXSize(Constants.GATE_LENGTH);
			mod.setYSize(Constants.GATE_HEIGHT);
			break;
		case INPUT_SYM:
		case OUTPUT_SYM:
			mod.setXSize(Constants.SYSTERM_SIZE);
			mod.setYSize(Constants.SYSTERM_SIZE);
			break;
		case BLOCK:
		default:
			mod.setXSize(Constants.ICON_SIZE);
			mod.setYSize(Constants.ICON_SIZE);
			break;
		}*/
	}

	private static Map<String, ModuleModel> registry = new HashMap<String, ModuleModel>();
	
	static {
		registry.put("IN",  new ModuleModel("IN",  Constants.SYSTERM_SIZE, Constants.SYSTERM_SIZE));
		registry.put("OUT", new ModuleModel("OUT", Constants.SYSTERM_SIZE, Constants.SYSTERM_SIZE));
		
		registry.put("AND", new ModuleModel("AND", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
		registry.put("NAND", new ModuleModel("NAND", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
		registry.put("OR", new ModuleModel("OR", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
		registry.put("NOR", new ModuleModel("NOR", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
		registry.put("XOR", new ModuleModel("XOR", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
		registry.put("XNOR", new ModuleModel("XNOR", Constants.GATE_LENGTH, Constants.GATE_HEIGHT));
	}

	public static ModuleModel getModel(String gateType) {
		ModuleModel model = registry.get(gateType);
		if (model == null) {
			model = new ModuleModel(gateType, Constants.ICON_SIZE, Constants.ICON_SIZE);
		}
		return model;
	}
}
